﻿using UnityEngine;

namespace HBFramework
{
    /// <summary>
    /// GameObject池
    /// </summary>
    public class GameObjectPool : BasePool<GameObject>
    {
        public GameObject Prefab { get; private set; }
        public Transform ParentTransform { get; private set; }

        public GameObjectPool(GameObject prefab, Transform parentTransform = null)
        {
            Prefab = prefab;
            ParentTransform = parentTransform;
        }

        protected override GameObject CreateObject(params object[] args)
        {
            var go = GameObject.Instantiate(Prefab.gameObject, parent: ParentTransform);
            return go;
        }

        protected override void OnRent(GameObject instance, params object[] args)
        {
            instance.SetActive(true);
        }

        protected override void OnRecycle(GameObject instance)
        {
            instance.SetActive(false);
        }

        protected override void OnRelease(GameObject instance)
        {
            GameObject.Destroy(instance);
        }
    }
}